package com.skyyan.netty.jjf.client.handler;

import cn.hutool.core.util.HexUtil;
import com.skyyan.netty.jjf.client.MessageHandler;
import com.skyyan.netty.jjf.protocol.Message;
import com.skyyan.netty.jjf.protocol.RegisterMessage;

/**
 * 注册消息处理器
 */
public class RegisterMessageHandler implements MessageHandler {
    @Override
    public boolean canHandle(Message msg) {
        return msg instanceof RegisterMessage;
    }
    
    @Override
    public void handle(Message msg) {
        if (msg instanceof RegisterMessage.Downlink) {
            RegisterMessage.Downlink downlink = (RegisterMessage.Downlink) msg;
            System.out.println("注册下行报文:");
            System.out.println("  设备注册号: " + HexUtil.encodeHexStr(downlink.getDeviceRegId()));
        } else {
            System.out.println("注册上行报文");
        }
    }
}